#ifndef APP_DATA_H
#define APP_DATA_H
#include "main.h"

#define FEED_VALUE_MAX      (0x0A)
#define FEED_VALUE_MIN      (0x01)

#define BAT_LOW_POWER_ALARM_PERCENT     (15)
#define BAT_LOW_POWER_OFF_PERCENT       (1)

typedef enum {
    WIFI_FAST_CONF,
    WIFI_AP_CONF,
    WIFI_STA_DISCONN,
    WIFI_STA_CONN,
    WIFI_NET_OK,
    WIFI_LOW_POWER,
    WIFI_AP_BLE_CONF,
} wifi_state_t;

typedef enum {
    TUYA_NET_NONE,
    TUYA_NET_OK,    // 网络ok
} tuya_net_t;

typedef enum {
    SLEEP_NONE,     // 非睡眠
    SLEEP_LED_ON,   // 睡眠led 亮
    SLEEP_LED_OFF,  // 睡眠led 灭
} dev_sleep_t;

typedef enum {
    FACTORY_NONE,
    FACTORY_ENTER,
} factory_state_t;

typedef enum {
    SHUTDOWN_NONE,
    SHUTDOWN_OK,    // 关机
} dev_shutdown_t;

typedef enum {
    POWER_OK,       // 电源ok
    POWER_LOW,      // 电源低电量
    POWER_OFF,      // 电源低电量关闭
} power_state_t;

typedef enum {
    DC_TYPE,        // DC 电源
    BAT_TYPE,       // BAT 电源
} power_atype_t;

typedef struct {
    dev_sleep_t state;  // 睡眠状态
    unsigned int time;  // 状态时间
} sleep_mgr_t;

typedef struct {
    factory_state_t state;
} dev_factory_t;

typedef struct {
    tuya_net_t      tuya_net;           // 网络
    sleep_mgr_t     sleep;              // 睡眠管理
    power_atype_t   type;               // 电源类型
    power_state_t   power;              // 电源状态
    dev_shutdown_t  shutdown;           // 关机状态
    unsigned short  battery;            // 电池电量 ADC 值
    unsigned char   record_duration;    // 录音时长
    dev_factory_t   factory;
} dev_value_t;

void app_data_read_from_flash(void);
void app_data_write_to_flash(void);

extern dev_value_t *dev_obj;
#endif